package com.markus.code.exam.aiqiyi;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/13 15:34
 * todo:
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String s = scanner.nextLine();
            String[] str = s.split(" ");
            int nums[] = new int[str.length];
            for (int i=0;i<nums.length;i++){
                nums[i] = Integer.parseInt(str[i]);
            }
            List<List<Integer>> lists = process(nums);
            for (List<Integer> list : lists) {
                for (Integer integer : list) {
                    System.out.print(integer+" ");
                }
                System.out.println();
            }
        }
    }
    public static List<List<Integer>> process(int []nums){
        List<List<Integer>> ans = new ArrayList<>();
        if (nums == null || nums.length == 0){
            return ans;
        }
        Arrays.sort(nums);
        for (int i=0;i<nums.length;i++){
            if (i>0 && nums[i] == nums[i-1]){
                //过滤相同数值引起的重复
                continue;
            }
            int l = i+1,r=nums.length-1,sum=0-nums[i];
            while(l < r){
                if (nums[l] + nums[r] == sum){
                    ans.add(Arrays.asList(nums[i],nums[l++],nums[r--]));
                    while(r > l && nums[l] == nums[l-1]){
                        l++;
                    }
                    while(r > l && nums[r] == nums[r+1]){
                        r--;
                    }
                }else if (nums[l]+nums[r] > sum){
                    r--;
                }else {
                    l++;
                }
            }
        }
        return ans;
    }
}
